/*****************************************************************************
 *   Copyright 2005 Tim A Wang
 *
 *   Licensed under the Apache License, Version 2.0 (the "License");
 *   you may not use this file except in compliance with the License.
 *   You may obtain a copy of the License at
 *
 *       http://www.apache.org/licenses/LICENSE-2.0
 *
 *   Unless required by applicable law or agreed to in writing, software
 *   distributed under the License is distributed on an "AS IS" BASIS,
 *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *   See the License for the specific language governing permissions and
 *   limitations under the License.
 *
 ****************************************************************************/
package com.jb.web.bean.content;

import com.jb.web.context.WebContext;
import com.jb.web.renderer.RendererImpl;

import com.jb.faces.component.UIComponent;


public class SoundRenderer extends RendererImpl {
    public StringBuffer renderBegin(WebContext pCtx, UIComponent itemToRender) {
        Sound hItem = (Sound) itemToRender;
        String url = this.evaluate(pCtx, hItem, hItem.getLocation());
        StringBuffer htmlBuffer = new StringBuffer("");

        if (isVisible(pCtx, hItem) && (url != null) && (url.length() != 0)) {
            htmlBuffer.append("<script >\n");
            htmlBuffer.append("\tJB.playBackground('" + url + "','" + hItem.loop + "');");
            htmlBuffer.append("</script >\n");
        }

        if (!pCtx.isRunTime()) {
            htmlBuffer.append("<div ").append(getEditScript(pCtx, hItem))
                      .append(addTagProperty("style", hItem.getStyle(pCtx), null)).append(" >");
            htmlBuffer.append("<img src=\"resources/images/palette/sound.gif\"")
                      .append(addTagProperty(" style", hItem.getStyle(pCtx), null)).append(getEditScript(pCtx, hItem))
                      .append(" />");
            htmlBuffer.append("</div>");
        }

        return htmlBuffer;
    }

    public StringBuffer renderChildren(WebContext pCtx, UIComponent itemToRender) {
        return new StringBuffer();
    }

    public StringBuffer renderEnd(WebContext pCtx, UIComponent itemToRender) {
        return new StringBuffer();
    }
}
